import { CommontListResp } from '@/api/types'
import request, { ApiResponse } from '@/utils/service/request'
import {
  Author,
  AuthWorkItem,
  GetAuthWorksReq,
  QueryAuthorReq,
  UpdateAuthorStatusReq,
} from './model/authorModel'

export enum AuthorApi {
  /** 查询作者列表 */
  QUERY_AUTH = '/paixin-admin/author/search',
  /** 更新作者审核、解约状态 */
  UPDATE_AUTHOR_STATUS = '/paixin-admin/author/updateStatus',
  /** 获取作者下的作品 */
  QUERY_AUTH_WORKS = '/paixin-admin/author/getAscList',
}

export function fetchAuthList(body: QueryAuthorReq) {
  body.type = true
  return request.post<ApiResponse<CommontListResp<Author>>>(
    AuthorApi.QUERY_AUTH,
    body
  )
}

export function updateAuthorStatus(body: UpdateAuthorStatusReq) {
  return request.post<ApiResponse<null>>(
    AuthorApi.UPDATE_AUTHOR_STATUS,
    body
  )
}

export function fetchAuthWorks(body: GetAuthWorksReq) {
  if (!body.checked) {
    body.checked = '0'
  }
  return request.post<ApiResponse<AuthWorkItem[]>>(
    AuthorApi.QUERY_AUTH_WORKS,
    body
  )
}
